import java.util.Stack;

public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;
    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }
    public void push(int val) {
        stack.push(val);
        if (minStack.empty())
        {
            minStack.push(val);
        }
        else{
            int topval = minStack.peek();
            if (val <= topval)
            {
                minStack.push(val);
            }
        }

    }
    public void pop() {
        if(stack.peek() == minStack.peek())
        {
            stack.pop();
            minStack.pop();
        }
        else
            stack.pop();
    }
    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
};

